home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 1 / QRZ Ham Radio Callsign Database - December 1993.iso / ucsd / packet / tcpip / amiga / asrc29k.lha / tcpdump.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-08  |  1.6 KB  |  74 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "netuser.h"
  5. #include "internet.h"
  6. #include "timer.h"
  7. #include "tcp.h"
  8. #include "ip.h"
  9. #include "trace.h"
  10.  
  11. /* TCP segment header flags */
  12. static char *Tcpflags[] = {
  13.     "FIN",    /* 0x01 */
  14.     "SYN",    /* 0x02 */
  15.     "RST",    /* 0x04 */
  16.     "PSH",    /* 0x08 */
  17.     "ACK",    /* 0x10 */
  18.     "URG"    /* 0x20 */
  19. };
  20.  
  21. /* Dump a TCP segment header. Assumed to be in network byte order */
  22. void
  23. tcp_dump(fp,bpp,source,dest,check)
  24. FILE *fp;
  25. struct mbuf **bpp;
  26. int32 source,dest;    /* IP source and dest addresses */
  27. int check;        /* 0 if checksum test is to be bypassed */
  28. {
  29.     struct tcp seg;
  30.     struct pseudo_header ph;
  31.     int16 csum;
  32.  
  33.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  34.         return;
  35.  
  36.     /* Verify checksum */
  37.     ph.source = source;
  38.     ph.dest = dest;
  39.     ph.protocol = TCP_PTCL;
  40.     ph.length = len_p(*bpp);
  41.     csum = cksum(&ph,*bpp,ph.length);
  42.  
  43.     ntohtcp(&seg,bpp);
  44.  
  45.     fprintf(fp,"TCP: %u->%u Seq x%lx",seg.source,seg.dest,seg.seq,seg.ack);
  46.     if(seg.flags.ack)
  47.         fprintf(fp," Ack x%lx",seg.ack);
  48.     if(seg.flags.urg)
  49.         fprintf(fp," %s",Tcpflags[5]);
  50.     if(seg.flags.ack)
  51.         fprintf(fp," %s",Tcpflags[4]);
  52.     if(seg.flags.psh)
  53.         fprintf(fp," %s",Tcpflags[3]);
  54.     if(seg.flags.rst)
  55.         fprintf(fp," %s",Tcpflags[2]);
  56.     if(seg.flags.syn)
  57.         fprintf(fp," %s",Tcpflags[1]);
  58.     if(seg.flags.fin)
  59.         fprintf(fp," %s",Tcpflags[0]);
  60.  
  61.     fprintf(fp," Wnd %u",seg.wnd);
  62.     if(seg.flags.urg)
  63.         fprintf(fp," UP x%x",seg.up);
  64.     /* Print options, if any */
  65.     if(seg.mss != 0)
  66.         fprintf(fp," MSS %u",seg.mss);
  67.     if(check && csum != 0) {
  68.         Tcp_mib[16].value.integer ++;
  69.         fprintf(fp,"\nTCP: CHECKSUM ERROR (%u)",csum);
  70.     }
  71.     fputc('\n',fp);
  72. }
  73.  
  74.